<?php
	/**
	 * Hi, and welcome to the http://www.sussex.ac.uk/skillcloud/ skillcloud class.
	 * Basically, it controls what skills you display to the user, based on their unique id.
	 * index.php instantiates this class, and calls its methods to populate the template with information.
	 * 
	 * 
	 * The interface skillcloud_interface defines the methods your skillcloud class must have.
	 *  
	 * This skillcloud template uses some static data which we have included in the class skillcloud_demo.
	 * 
	 * Of course in Sussex we conect to a database which holds our info, and you probably want to do the same.
	 *  HOW ??
	 *  well, by default in this template your running skillcloud_demo, which has some hardcodded info to display in.
	 *  
	 *  check the example below called class skillcloud_remote
	 *  as you can see it extends the skillcloud class, which implements the skillcloud_interface.
	 *  Add your own methods for fetching your data, and as long as you also provide the functions 
	 *  listed in skillcloud_interface for geting the data, you're good.
	 *  
	 * 
	 */
	
	
	/**
	 * Interface desciption for skillcloud class  
	 * @param $unique_id Object
	 * 
	 */
	interface skillcloud_interface {
		public function __construct($unique_id); // the unique id to identify your user
		public function get_user_skills(); // get the skills this user has
		public function get_atoz(); // get a range (a to z), where chars which correspond to the initial letters of the users skils list are flagged
	}
	
	
	/**
	 * Abstarct skillcloud class
	 * Implements skillcloud_interface
	 * 
	 */
	abstract class skillcloud implements skillcloud_interface { 
			
			protected $user_id; // the unique id to identify your user
			protected $skills; // get the skills this user has
			protected $atoz; // get a range (a to z), where chars which correspond to the initial letters of the users skils list are flagged
			
			
			function __construct($unique_id) {
				$this->user_id = $unique_id; 
			}
			
			
			public function get_atoz(){	
				return $this->atoz;
			}
			
			
			// is this case sensitive ?
			protected function set_atoz($skills) {
				$all_atoz = range('a', 'z'); // array containing the chars a ot z
				$skills_atoz; // the first letters of each skill, in alphabetical order
				$atoz; // our output of the coresponding flagged set
				
				// loop through $this->skills, creating a unique array of first letter
				foreach ($skills as $skill) {
					$skills_atoz[] = $skill['0'];
				}
				$skills_atoz = array_unique($skills_atoz);
				
				// if $all_atoz[x] is a member of $skills_atoz add 'member_' to $all_atoz[x] in array $atoz
				foreach ($all_atoz as $letter) {
					if( in_array($letter,$skills_atoz) ) {
						$atoz[] = 'member_'.$letter;
					}
					else {
						$atoz[] = $letter;
					}
				}			
				$this->atoz =  $atoz;
				
		 	}
		
	}
	
/*
	// an example of how to extend the skillcloud class
 	class skillcloud_remote extends skillcloud {
		public function get_skills_from_database($user_id){
			// contect to your database and fetch the users skills
			// or fetch it from somewhere else!
			return $user_skills;
		}
		
	}
*/
	
	/**
	 * A hardcoded set of skills for demo purposes 
	 * 
	 */
	class skillcloud_demo extends skillcloud {
				
			static protected $default_skills = array('analysis',
												'critical assessment',
												'data analysis and interpretation',
												'ethical awareness and sensitivity',
												'flexibility',
												'independent thinking',
												'information technology',
												'initiative',
												'intellectual debate',
												'interpersonal skills',
												'leadership',
												'literature review',
												'motivation',
												'numeracy',
												'organisation and time management',
												'practical',
												'presentation',
												'problem solving',
												'professional development',
												'research',
												'self awareness',
												'self confidence',
												'self management',
												'teamwork',
												'verbal communication',
												'workplace awareness',
												'written communication'); // a default set of skills for demo purposes
												
			function __construct($unique_id) {
				parent::set_atoz(self::$default_skills); // call the set a to z function of skillcloud, passing it the $default_skills array
			}

			public function get_user_skills(){
				return self::$default_skills;
			}	
	
	
	}	
?>
